﻿using System.Web.Mvc;
using SharePointEditor.BusinessDefinitions.Serialization;

namespace SharePointEditor.Web.Extensions
{
    public static class HtmlHelperExtensions
    {
        public static string AjaxCall(this HtmlHelper h,
            string actionName, 
            object jsonObject, 
            string divToChange)
        {
            return AjaxCall(h, "Ajax", actionName, jsonObject, divToChange);
        }

        public static string AjaxCall(this HtmlHelper h, 
            string controllerName, 
            string actionName, 
            object jsonObject, 
            string divToChange)
        {
            var json = JSONSerializer.Serialize(jsonObject);
            var properties = "'"+controllerName+"','"+actionName+"','"+json+"','"+divToChange+"'";
            var javaScript = "AjaxCall(" + properties + ");";
            return javaScript;
        }
    }
}